import { ref, onMounted, onUnmounted } from "vue";
export function useScrollEvent(callback: any) {
  /* 监听滚动事件 */
  onMounted(() => {
    window.addEventListener("scroll", handleScroll);
  });

  /* 移除滚动事件监听器（例如，在卸载组件时） */
  onUnmounted(() => {
    window.removeEventListener("scroll", handleScroll);
  });

  const scrollTop = ref(0);
  const handleScroll = () => {
    scrollTop.value = window.pageYOffset || document.documentElement.scrollTop;
    // 处理滚动
    callback && callback();
  };

  return {
    scrollTop,
  };
}
